package _2022.hot100._46_全排列;

import java.util.ArrayList;
import java.util.List;

/**
 * @author： YHSimon
 * @date： 2022-04-11 15:03
 */
public class Solution {
    public List<List<Integer>> permute(int[] nums) {
        List<List<Integer>> combinations = new ArrayList<>();
        List<Integer> combine = new ArrayList<>();
        boolean[] use = new boolean[nums.length];
        solve(combinations, combine, nums, use);
        return combinations;
    }

    public void solve(List<List<Integer>> combinations, List<Integer> combine, int[] nums, boolean[] use) {
        if (combine.size() == nums.length) {
            combinations.add(new ArrayList<>(combine));
        }
        for (int i = 0; i < nums.length; i++) {
            if (!use[i]) {
                combine.add(nums[i]);
                use[i] = true;
                System.out.println("递归前=》"+combine.toString());
                solve(combinations, combine, nums, use);
                System.out.println("递归后=》"+combine.toString());
                use[i] = false;
                combine.remove(combine.size() - 1);
            }
        }
    }

    public static void main(String[] args) {
        Solution s = new Solution();
        System.out.println(s.permute(new int[]{1,2,3}).toString());
    }
}
